package com.at.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * @author cdhuangchao3
 * @date 2023/3/19 9:52 PM
 */
object Spark22_RDD_leftOuterJoin {

  def main(args: Array[String]): Unit = {
    // 环境准备
    val sparkConf = new SparkConf()
      .setMaster("local[*]")
      .setAppName("Operator")
    val sc = new SparkContext(sparkConf)

    // TODO 算子 - key - value类型
    val rdd1 = sc.makeRDD(List(
      ("a", 1), ("b", 2), ("c", 3)
    ), 2)
    val rdd2 = sc.makeRDD(List(
      ("a", 4), ("b", 5)//, ("c", 6)
      , ("d",7)
    ), 2)

    val joinRDD = rdd1.leftOuterJoin(rdd2)
    val joinRDD2 = rdd1.rightOuterJoin(rdd2)
    joinRDD.collect().foreach(println)
    joinRDD2.collect().foreach(println)

    sc.stop()
  }

}
